import * as actionTypes from '../actions/ActionTypes';

import {handleActions} from 'redux-actions';

//查询公司发布的职位
const defData = {
    postionList: [],
    isloading: true//是否读取ing1
}
export const Sel_P_sendReducer = handleActions({
    [actionTypes.SEL_P_SEND]: {
        next(state, action) {
            if (action.payload.page != 1) {
                action.payload.postionList = state.data.postionList.concat(action.payload.postionList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData};
        }
    }
}, {ret: true, isloading: true, statusText: '默认', data: defData});

//公司发布职位查询公司状态
const defData1 = {
    xzPostion: {},
    isloading: true//是否读取ing1
}
export const ForPublishReducer = handleActions({
    [actionTypes.FORPUBLISHMOB]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData1};
        }
    }
}, {ret: true, statusText: '默认', data: defData1});

//发布职位
const defData2 = {
    msg: {},
    isloading: true//是否读取ing1
}
export const InsertPostionReducer = handleActions({
    [actionTypes.INSERT_POSTION]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData2};
        }
    }
}, {ret: true, statusText: '默认', data: defData2});

//公司职位详情
const defData3 = {
    xzPostion: {},
    isloading: true//是否读取ing1
}
export const Sel_Pos_ComReducer = handleActions({
    [actionTypes.SEL_POS_COM]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData3};
        }
    }
}, {ret: true, statusText: '默认', data: defData3});

//公司职位详情
const defData4 = {
    msg: {},
    isloading: true//是否读取ing1
}
export const UpdateStatePasueMobReducer = handleActions({
    [actionTypes.UPDATE_STATE_PASUE_MOB]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData4};
        }
    }
}, {ret: true, statusText: '默认', data: defData4});

//修改添加公司信息
const defData5 = {
    msg: {},
    isloading: true//是否读取ing1
}
export const Edit_CompanyReducer = handleActions({
    [actionTypes.EDIT_COMPANY_MOB]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData5};
        }
    }
}, {ret: true, statusText: '默认', data: defData5});

//20171219-王继顺
//企业职位浏览人数
const defData9 = {
    resumeList: [],
    isloading: true,
};
export const SelPosBrowseReducer = handleActions({
    [actionTypes.SEL_POS_BROWSE]: {
        next(state, action) {
            if (action.payload.page !== 1) {
                action.payload.resumeList = state.data.resumeList.concat(action.payload.resumeList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw() {
            return {ret: false, isloading: false, statusText: "报错", data: defData9};
        }
    }
}, {ret: true, isloading: true, statusText: '默认', data: defData9});